import Router from 'koa-router'
import axios from '../utils/axios'

const router = new Router({ prefix: '/shop' })

router.get('/foodClassify', async ctx => {
  const {
    status,
    data: { code, data }
  } = await axios.get(`https://suhao.online/elem/api/shop/foodClassify`)
  if (status === 200 && code === 0) {
    ctx.body = {
      data
    }
  } else {
    ctx.body = {
      data: []
    }
  }
})

router.get('/shopList', async ctx => {
  const {
    status,
    data: { code, data }
  } = await axios.get(
    `https://suhao.online/elem/api/shop/shopList?pageSize=20&pageIndex=1`
  )
  if (status === 200 && code === 0) {
    ctx.body = {
      shop: data
    }
  } else {
    ctx.body = {
      shop: []
    }
  }
})

export default router
